from dao.user_message_dao import UserMessageDao
from model.user_message import UserMessage

class UserMessageService:
    def __init__(self, session):
        self.session = session

    def add_message(self, message):
        dao = UserMessageDao(self.session)
        dao.add(message)

    def add(self,d={}):
        dao = UserMessageDao(self.session)
        message = UserMessage()
        for k, v in d.items():
            setattr(message, k, v)
        dao.add(message)

    def update_read(self, message_id):
        dao = UserMessageDao(self.session)
        dao.update_read(message_id=message_id)

    def get_messages_by_user_id(self, user_id):
        dao = UserMessageDao(self.session)
        result = dao.get_messages_by_user_id(user_id=user_id)
        if result:
            return result
        else:
            return None

    def get_send_by_job_id(self, job_id):
        dao = UserMessageDao(self.session)
        count = dao.get_send_by_job_id(job_id=job_id)
        return count